package com.leo;

import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.SpawnData;
import com.leo.component.SpriteComponent;
import com.leo.constant.Dir;
import com.leo.entity.SpriteEntityFactory;
import javafx.scene.input.KeyCode;

/**
 * @Author: wangss
 * @CreateTime: 2023-06-06  22:02
 * @Description: TODO
 */
public class SpriteAnimateionApp extends GameApplication {

    private SpriteComponent component;

    @Override
    protected void initSettings(GameSettings settings) {

    }

    @Override
    protected void initGame() {
        FXGL.getGameWorld().addEntityFactory(new SpriteEntityFactory());
        Entity sprite = FXGL.spawn("sprite", new SpawnData(100, 100));
        component = sprite.getComponent(SpriteComponent.class);
    }

    @Override
    protected void initInput() {
        FXGL.onKey(KeyCode.UP, () -> component.moveDir(Dir.UP));
        FXGL.onKey(KeyCode.DOWN, () -> component.moveDir(Dir.DOWN));
        FXGL.onKey(KeyCode.LEFT, () -> component.moveDir(Dir.LEFT));
        FXGL.onKey(KeyCode.RIGHT, () -> component.moveDir(Dir.RIGHT));
    }

    public static void main(String[] args) {
        launch(args);
    }
}
